﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using Topshelf;
using Topshelf.Logging;

using YTS.Logic.Log;
using YTS.Logic.IO;

namespace RunQuartzConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            //EnableFunction();
            EnableService();
        }

        public static void EnableFunction()
        {
            string logPath = YTS.Logic.IO.FilePathExtend.ToAbsolutePath("logs/command.log");
            ILog log = new FilePrintLog(logPath, Encoding.UTF8);
            var help = new CommandExecutionHelp(log);
            string ExePath = "../DingDingHintAPP/DingDingHintAPP.exe";
            string WindowLoginUserName = "Administrator";
            help.OpenDingDingHintAPP_ApplicationLoader(ExePath, WindowLoginUserName);
        }

        public static void EnableService()
        {
            /*
             * C#-TopShelf服务创建和运行 
             * https://www.cnblogs.com/ywkcode/p/13239138.html
             * 
             * http://docs.topshelf-project.com/en/latest/configuration/quickstart.html
             */

            const string ServiceName = "DingDingHintAPPTimerService";
            // 配置和运行宿主服务
            HostFactory.Run(x =>
            {
                x.Service<CommandScriptService>();
                // 服务通过本地系统账号运行
                x.RunAsLocalSystem();
                // 服务信息描述
                x.SetDescription("DingDingHintAPP Timer Windows Service");
                // 服务显示名称
                x.SetDisplayName(ServiceName);
                // 服务名称
                x.SetServiceName(ServiceName);
                // 启用日志记录
                x.UseNLog();
            });
        }
    }
}
